<?php
//权限树形结构图
function getAuthTree($arr,$pid=0,$level=0){
	static $result = array();
	foreach($arr as $value){
		if($value['auth_pid']==$pid){
			$value['level'] = $level;
			$result[] = $value;
			getAuthTree($arr,$value['auth_id'],$level+1);
		}
	}
	return $result;
}
/****************************************阿里OSS视频上传**********************************/
function new_oss(){
	vendor('Alioss.autoload');
	$config = C('ALIOSS_CONFIG');
	$oss = new \OSS\OssClient($config['KEY_ID'],$config['KEY_SECRET'],$config['END_POINT']);
	return $oss;
}

function oss_upload($path){
	// var_dump($path);die;
	$bucket = C('ALIOSS_CONFIG.BUCKET');
	$oss_path = ltrim($path['0'],'./');
	$path = './'.$oss_path;
	
	if(file_exists($path)){
		$oss = new_oss();
		$oss->uploadFile($bucket,$oss_path,$path);
		unlink($path);
		return true;
	}
	return false;
 }
/***************************************图片上传*******************************/
function app_upload_image($path,$maxSize=52428800){
    ini_set('max_execution_time', '0');
    // 去除两边的/
    // $path=trim($path,'.');
    // $path=trim($path,'/');
    // var_dump($path);die;
    $config=array(
        'rootPath'  =>'./',         //文件上传保存的根路径
        'savePath'  =>'./Upload/image'.$path.'/',   
        'exts'      => array('jpg', 'gif', 'png', 'jpeg','bmp','pdf','doc','xlsx','docx','ppt','txt'),
        'maxSize'   => $maxSize,
        'autoSub'   => true,
        );
    $upload = new \Think\Upload($config);// 实例化上传类
    $info = $upload->upload();
    // var_dump($info);die;
    if($info) {
        foreach ($info as $k => $v) {
            $data[]=trim($v['savepath'],'.').$v['savename'];
        }
         // var_dump($data);die;
        return $data;
        // $data[]=trim($info['savepath'],'.').$info['savename'];
       
        // return $data;
       
    }
}
/**************************************阿里OSSURL********************************/
function get_url($path){
	if(empty($path)){
		return '';
	}
	if(strpos($path,'http://')===false){
		return $path;
	}
	$bucket = C('ALIOSS_CONFIG.BUCKET');
	return 'http://'.$bucket.'.oss-cn-beijing.aliyuncs.com'.$path['0'];
}

 /***************************************单个文件上传*******************************/
function app_upload_onefile($path,$maxSize=52428800){
    ini_set('max_execution_time', '0');
    // 去除两边的/
    // $path=trim($path,'.');
    // var_dump($path);
    echo "<br />";
    $config=array(
        'rootPath'  =>'./',         //文件上传保存的根路径
        'savePath'  =>'./Upload/image'.$path.'/',   
        'exts'      => array('jpg', 'gif', 'png', 'jpeg','bmp','pdf','doc','xlsx','docx','ppt','txt'),
        'maxSize'   => $maxSize,
        'autoSub'   => true,
        );
    $upload = new \Think\Upload($config);// 实例化上传类
    $info = $upload->uploadOne($path);
    $data[]=trim($info['savepath'],'.').$info['savename'];

      return $data;

}

function Getzimu($str) 
{ 
$str= iconv("UTF-8","gb2312", $str);//如果程序是gbk的，此行就要注释掉 
if (preg_match("/^[\x7f-\xff]/", $str)) //判断是否全是中文
{
$fchar=ord($str{0}); 
if($fchar>=ord("A") and $fchar<=ord("z") )return strtoupper($str{0}); 
$a = $str; 
$val=ord($a{0})*256+ord($a{1})-65536; 
if($val>=-20319 and $val<=-20284)return "A"; 
if($val>=-20283 and $val<=-19776)return "B"; 
if($val>=-19775 and $val<=-19219)return "C"; 
if($val>=-19218 and $val<=-18711)return "D"; 
if($val>=-18710 and $val<=-18527)return "E"; 
if($val>=-18526 and $val<=-18240)return "F"; 
if($val>=-18239 and $val<=-17923)return "G"; 
if($val>=-17922 and $val<=-17418)return "H"; 
if($val>=-17417 and $val<=-16475)return "J"; 
if($val>=-16474 and $val<=-16213)return "K"; 
if($val>=-16212 and $val<=-15641)return "L"; 
if($val>=-15640 and $val<=-15166)return "M"; 
if($val>=-15165 and $val<=-14923)return "N"; 
if($val>=-14922 and $val<=-14915)return "O"; 
if($val>=-14914 and $val<=-14631)return "P"; 
if($val>=-14630 and $val<=-14150)return "Q"; 
if($val>=-14149 and $val<=-14091)return "R"; 
if($val>=-14090 and $val<=-13319)return "S"; 
if($val>=-13318 and $val<=-12839)return "T"; 
if($val>=-12838 and $val<=-12557)return "W"; 
if($val>=-12556 and $val<=-11848)return "X"; 
if($val>=-11847 and $val<=-11056)return "Y"; 
if($val>=-11055 and $val<=-10247)return "Z"; 
} 
else 
{ 
$e =  substr($str,0,1);
$e = strtoupper($e);
return $e; 
} 
}